package com.zyasdk.util.root;

import java.util.LinkedList;
import java.util.Collections;
import java.util.List;

import android.content.Context;

public class RLinkedList {
    static List<RApi> rootList = Collections.synchronizedList(new LinkedList<RApi>());
    static RApi RInstance = null;
    public boolean add(RApi object){
    	return rootList.add(object);
    }
    
    public boolean isR(Context mcontext){
    	if(rootList.isEmpty()) return false;
    	for(int i=0;i<rootList.size();i++){
    		if(rootList.get(i).isR(mcontext)){
    			return true;
    		}
    	}
    	return false;
    }
    
    public Process getR(Context mcontext){
    	if(rootList.isEmpty()) return null;
    	for(int i=0;i<rootList.size();i++){
    		RApi rootInstance=rootList.get(i);
    		if(rootInstance.isR(mcontext)){
    			RInstance = rootInstance;
    			return rootInstance.getR(mcontext);
    		}
    	}
    	RInstance = null;
    	return null;
    }
    
    public void closeP(Process p){
    	if(null != RInstance){
    		RInstance.closeP(p);
    	}
    }
}

